package com.wshl.aijiuunion.controller.activity;

import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;

import com.wshl.aijiuunion.BaseActivity;
import com.wshl.aijiuunion.R;
import com.wshl.aijiuunion.utils.share.ShareManager;
import com.wshl.aijiuunion.utils.share.Tools;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created buy 风凊扬 on 2019/10/31 0031
 */
public class ShareTestActivity extends BaseActivity {
    @BindView(R.id.btn_wx)
    Button btnWx;
    @BindView(R.id.btn_find)
    Button btnFind;
    @BindView(R.id.btn_qq)
    Button btnQq;
    @BindView(R.id.btn_zone)
    Button btnZone;

    private boolean isShareImg = false;
    private String[] stringItem = {"https://gd2.alicdn.com/imgextra/i1/2259324182/TB2sdjGm0BopuFjSZPcXXc9EpXa_!!2259324182.jpg",
            "http://img4.tbcdn.cn/tfscom/i1/2259324182/TB2ISF_hKtTMeFjSZFOXXaTiVXa_!!2259324182.jpg",
            "http://img2.tbcdn.cn/tfscom/i1/2259324182/TB2NAMmm00opuFjSZFxXXaDNVXa_!!2259324182.jpg"};
    private ShareManager shareManager;
    private List<String> stringList = new ArrayList<>();

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_share;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);

        for (int i = 0; i < stringItem.length; i++) {
            stringList.add(stringItem[i]);
        }
    }

    @OnClick({R.id.btn_wx, R.id.btn_find, R.id.btn_qq, R.id.btn_zone})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_wx:
                share(0,"","wchat");
                break;
            case R.id.btn_find:
                share(1,"微信分享朋友圈的说明","wchat");
                break;
            case R.id.btn_qq:
                share(0,"QQ好友分享的说明","qq");
                break;
            case R.id.btn_zone:
                share(1,"QQ空间分享的说明","qq_zone");
                break;
        }
    }


    private void share(int i, String s, String mType) {
        isShareImg = true;
        shareManager = new ShareManager(this);
        shareManager.setShareImage(i, stringList, s, mType);
    }


    @Override
    protected void onResume() {
        super.onResume();

        if (isShareImg) {
            isShareImg = false;
            File file = new File(Environment.getExternalStorageDirectory() + "/shareImg/");
            Tools.deletePic(file);
        }
    }
}
